<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <#assign path="${springMacroRequestContext.getContextPath()}">
    <link rel="stylesheet" href="${path}/layui/css/layui.css">
    <style>
        /* .layui-bg-black {
            width: 240px;
        } */
        .layui-nav-item {
            margin-top: 10px;
        }
        .layui-nav-item p {
            padding: 0 20px;
        }
        .box{
            margin-bottom: 40px;
        }
        .box p {
            margin-top: 40px;
            margin-left: 20px;
        }
        .box a {
            color: white;
        }
        .box a:hover {
            color: darkgray;
        }
        .layui-body {
            margin-top: 150px;
            margin-left: 450px;
        }
    </style>
</head>
<body class="layui-layout-body">
<!-- 左边导航部分 -->
<div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
        <ul class="layui-nav layui-nav-tree"  lay-filter="test">
            <div class="box">
                <p>${Session.user.userName} &nbsp (<a href="/login_out">退出</a>)</p>
                <p>${Session.user.userTrueName},你好</p>
            </div>
            <li class="layui-nav-item">
                <a href="/user/user_book_view">图书查询</a>
            </li>
            <li class="layui-nav-item ">
                <a href="/user/user_borrowing_view">借阅记录</a>
            </li>
            <li class="layui-nav-item layui-nav-itemed">
                <a href="/user/user_personal_view">个人信息</a>
            </li>
        </ul>
    </div>
</div>
<!-- 内容主体区域 -->
<div class="layui-body">
    <form class="layui-form" action="">
        <input name="userId" value="${Session.user.userId}" hidden>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="userName" lay-verify="required" lay-reqtext="用户名不可为空" placeholder="请输入您的用户名"
                       autocomplete="off" class="layui-input" style="width: auto;" id="userName" value="${Session.user.userName}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-block">
                <input type="text" name="userTrueName" lay-verify="required" lay-reqtext="用户真实姓名不可为空" placeholder="请输入您的真实姓名"
                       autocomplete="off" class="layui-input" style="width: auto;" id="userTrueName" value="${Session.user.userTrueName}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <#if  Session.user.sex == "男">
                <input type="radio" name="sex" value="男" title="男" checked>
                <input type="radio" name="sex" value="女" title="女">
                <#else>
                <input type="radio" name="sex" value="男" title="男">
                <input type="radio" name="sex" value="女" title="女" checked>
            </#if>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">注册时间</label>
            <div class="layui-input-block">
                <input type="text" readonly autocomplete="off" class="layui-input" style="width: auto;" value='${(Session.user.userCreateTime)?string("yyyy-MM-dd HH:mm:ss")}'>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">确认修改信息</button>
            </div>
        </div>
    </form>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="updatePassword">点击修改密码</button>
            </div>
        </div>
</body>
<script src="${path}/layui/layui.js"></script>
<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use(['element','form'], function(){
        var element = layui.element;
        var $ = layui.$;
        var form = layui.form;
        form.on('submit(formDemo)', function(data){
            // console.log(data);
            // layer.msg(JSON.stringify(data.field));
            // console.log(JSON.stringify(data.field));
            $.ajax({
                type: "post",
                url: "/user/updatePersonal",
                contentType: "application/json;charset=utf-8",
                data: JSON.stringify(data.field),
                dataType: "json",
                success: function (data) {
                    if(data.code > 0){
                        layer.msg(data.msg);
                    }else if(data.code == 0){
                        //刷新页面
                        location.reload();
                    }
                }
            });
            return false;
        });

        //注册修改密码监控
        $("#updatePassword").on('click', function(){
            layer.open({
                type:2
                ,title:"修改密码"
                ,content: "/user/updatePassword"
                ,area: ['400px','350px']
                ,btnAlign: 'c'
                ,cancel:function(index){
                    layer.close(index);
                }
                ,end:function () {
                    location.reload();
                }
            })
        });

    });
</script>

</body>
</html>